package com.uncp.comisiondeadmision.comprobantedepago.dao;

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


import com.uncp.comisiondeadmision.comprobantedepago.beans.HistorialIGVBean;
import com.uncp.comisiondeadmision.util.MySqlDBConn;



public class MySqlHistorialIgvDAO implements HistorialIgvDAO {
/*
	@Override
	public double calcularIgv() throws SQLException {
		Connection conn = null;
		PreparedStatement pst = null;
		
		ResultSet rs = null;
		
		double igv=-1;
		

		try {
			conn = new MySqlDBConn().getConnection();
			
			String sql="SELECT valor,fecha FROM historial_igv order by fecha desc limit 1";
			pst = conn.prepareStatement(sql);
			
			
			rs = pst.executeQuery();

			while (rs.next()) {
				
				igv=rs.getDouble("valor");
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null)	 rs.close();
			if (pst != null) pst.close();
			if (conn != null)conn.close();
		}
System.out.println("igv acaaa"+igv);
		return igv;
	}*/

	@Override
	public HistorialIGVBean CargarHistorialIgv() throws SQLException {
		HistorialIGVBean bean = null;
		String sql = "SELECT codigv,valor,fecha FROM historial_igv order by fecha desc limit 1";
		System.out.println("SENTENCIA SQL : " + sql);

		Connection conn = null;
		try {
			conn = new MySqlDBConn().getConnection();
			Statement pstm = conn.createStatement();
			ResultSet rst = pstm.executeQuery(sql);
			while (rst.next()) {
				bean = new HistorialIGVBean();
				bean.setIntCodIgv(rst.getInt(1));
				bean.setDblValor(rst.getDouble(2));
				bean.setStrFecha(rst.getString(3));	
			
			}

			rst.close();
			pstm.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			conn.close();
		}
		return bean;
	
	}
	}
	
	


